package com.shu.solr;

import java.io.File;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.nio.charset.Charset;
import java.util.concurrent.atomic.AtomicInteger;

import org.apache.commons.io.FileUtils;
import org.apache.solr.client.solrj.SolrQuery;
import org.apache.solr.client.solrj.StreamingResponseCallback;
import org.apache.solr.client.solrj.impl.HttpSolrClient;
import org.apache.solr.client.solrj.response.QueryResponse;
import org.apache.solr.common.SolrDocument;
import org.apache.solr.common.params.MapSolrParams;
import org.apache.solr.common.params.ModifiableSolrParams;
import org.apache.solr.common.params.SolrParams;

public class TestExportSolr {

	
	public static void main(String[] args) throws Throwable {
		final String solrUrl = "http://192.168.1.14:8984/solr";
		String fields = "";
		final String[] fl = fields.split("\\,");  
		HttpSolrClient build = new HttpSolrClient.Builder(solrUrl)
			    .withConnectionTimeout(10000)
			    .withSocketTimeout(60000)
			    .build();
		  
		File outfile = new File("C:\\Users\\Administrator\\Desktop\\1.txt");
		final PrintWriter writer = new PrintWriter(new OutputStreamWriter(  
		        FileUtils.openOutputStream(outfile)));  
		  
		final AtomicInteger count = new AtomicInteger(0);  
		SolrQuery query = new SolrQuery();
		query.setDistrib(false);  
		query.setFields(fields);  
		query.setRows(9999999); 
		
		QueryResponse result = build.queryAndStreamResponse(query,  
		        new StreamingResponseCallback() {  
		            @Override  
		            public void streamSolrDocument(SolrDocument doc) {  
		                // process doc  
		            }  
		  
		            public void streamDocListInfo(long numFound, long start,  
		                    Float maxScore) {  
		                 writer.println("numFound:" + numFound);  
		            }  
		        });  
		writer.close();  
		System.out.println("numFound:" + result.getResults().getNumFound());  
		build.close();  
	}

}
